package ws.very.util.mapdb.akka.wraper

import java.io.DataOutput
import java.io.DataInput

trait Serializable extends scala.Serializable

trait Serializer[A] extends Serializable with org.mapdb.Serializer[A] {
  def serialize(out: DataOutput, value: A): Unit

  def deserialize(in: DataInput, available: Int): A
  def fixedSize(): Int
}
class SerializerImpl[A](serializeFn: (DataOutput, A) => U)(deserializeFn: (DataInput, I) => A)(val fixedSize: I = -1) extends Serializer[A] {
  def serialize(out: DataOutput, value: A): Unit =
    serializeFn(out, value)
  def deserialize(in: DataInput, available: Int): A = deserializeFn(in, available)
}

object Serializer {

  case class str() extends SerializerImpl[S]({ (i, v) => i.writeUTF(v) })({ (i, _) => i.readUTF })()
  case class stringIntern() extends SerializerImpl[S]({ (i, v) => i.writeUTF(v) })({ (i, _) => i.readUTF.intern() })()
  case class long() extends SerializerImpl[Long]({ (i, v) => i.writeLong(v) })({ (i, a) => i.readLong() })(8)
}

trait BTreeKeySerializer[K]